package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Safety;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liux on 2017/3/7.
 */

public class SafetyListAdapter extends BaseAdapter {
    private List<Safety> datas;
    private Context context;
    private int type;

    public SafetyListAdapter(List<Safety> datas, Context context,int type) {
        this.context = context;
        this.datas = datas;
        this.type=type;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = LayoutInflater.from(context)
                    .inflate(R.layout.item_safety, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Safety safety = datas.get(position);
        if(type==1){
            holder.name1Title.setText("培训名称");
            holder.name2Title.setText("培训时间");
        }else{
            holder.name1Title.setText("演习名称");
            holder.name2Title.setText("演习时间");
        }
        holder.name1Content.setText(safety.getTheme());
        holder.name2Content.setText(safety.getStartDate()+" 至 "+safety.getEndDate());

        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.name1_title)
        HXTextView name1Title;
        @BindView(R.id.name1_content)
        HXTextView name1Content;
        @BindView(R.id.name2_title)
        HXTextView name2Title;
        @BindView(R.id.name2_content)
        HXTextView name2Content;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
